// 动态创建确认弹框
import { createVNode, render } from 'vue'
import XtxConfirm from './xtx-confirm.vue'

const divVNode = createVNode('div', { class: 'xtx-confirm-container' })
render(divVNode, document.body)

export default ({ title, message }) => {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      render(null, divVNode.el)
      resolve()
    }
    const cancelCallback = () => {
      render(null, divVNode.el)
      reject(new Error('用户点击了取消按钮'))
    }
    const div = createVNode(XtxConfirm, { title, message, confirmCallback, cancelCallback })
    render(div, divVNode.el)
  })
}
